//
//  Server.Github.swift
//  API
//
//  Created by ET|冰琳 on 2017/3/24.
//  Copyright © 2017年 IB. All rights reserved.
//

import Foundation
import ReactiveSwift
import Alamofire

let githubClientid = "a17a38adf8a960b4f112"
let githubClientsercret = "74455f2bba6cfb86779afbbc7892de86ba96fbf8"

// MARK: -
extension Server {
    struct Github { }
}


// MARK: - server
extension Server.Github {
    static let host = Server(scheme: "http", host: "api.github.com", basePath: "")
}

extension Server.Github {
    
    static func request(
        server: Server = Server.Github.host,
        path: Path,
        method: Alamofire.HTTPMethod = .get,
        parameters: Parameters? = nil,
        encoding: ParameterEncoding = URLEncoding.default,
        headers: HTTPHeaders? = nil)
        -> SignalProducer<Any, NSError>
    {
        let urlO = server.url(path)
        guard let url = urlO else {
            fatalError("please provide a right url")
        }
        return API.request(url, method: method, parameters: parameters, encoding: encoding, headers: headers).reactive.responseJSON()
    }
}



extension Path {
    static let oauth: Path = "login/oauth/authorize"
}


/*
 OAuth
 http://www.ietf.org/rfc/rfc2617.txt
 NSString *newPassword = @(encrypt_pwd);
 
 NSData *basicAuthCredentials = [[NSString stringWithFormat:@"%@:%@", CLIENTID, CLIENTSECRET] dataUsingEncoding:NSUTF8StringEncoding];
 
 NSString *base64AuthCredentials = [basicAuthCredentials base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)0];
 
 NSString *authorization = [NSString stringWithFormat:@"Basic %@", base64AuthCredentials];
 
 [API setGalaxySessionValue:authorization forHTTPHeaderField:@"Authorization"];
 
 RACSignal *sig = [[[API galaxySessionManager] rac_POST:[[UKURLManager sharedManager].baseIdentity stringByAppendingString:UKAPIUserToken] parameters:@{@"grant_type": @"password", @"username": username, @"password": password, @"scope": @"openid offline_access"} progress:nil] map:^AccessTokenEntity * (id value) {
 AccessTokenEntity *user = [AccessTokenEntity mj_objectWithKeyValues:value];
 return user;
 }];
 

 */

